package com.kele.common.exception;

import com.kele.common.model.response.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//Advice 通知  AOP
@Component
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共Exception异常处理类");
        return new Result(false,"1",e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result runtimeException(RuntimeException e){
        e.printStackTrace();
        System.out.println("调用了公共异常RuntimeException处理类");
        return new Result(false,"1",e.getMessage());
    }

    @ExceptionHandler(MyException.class)
    public Result myException(MyException e){
        e.printStackTrace();
        System.out.println("调用了公共异常MyException处理类");
        return new Result(false,"1",e.getMessage());
    }
}
